﻿@model Apps.Models.Flow.Flow_FormContentModel
@using Apps.Common;
@using Apps.Models.Flow;
@using Apps.Web.Core;
@using Apps.Models.Sys;
@using Apps.Models.Enum;
@using Apps.Locale;
@{
    ViewBag.Title = "创建";
    Layout = "~/Views/Shared/_Index_LayoutEdit2.cshtml";
    string html = ViewBag.Html.ToString();
    List<permModel> perm = null;
}

<script type="text/javascript">

    $.fn.serializeObject = function () {
        var ss =  this.serializeArray();
        var aa = { his: [], val: [], kg: [] };
        $.each(ss,function(o){
            if(aa.his.indexOf(this.name)>=0){
                var _obj = aa.val[aa.kg[this.name]];
                _obj.value = _obj.value+','+this.value;
            }else{
                aa.his.push(this.name);
                aa.kg[this.name] = o;
                aa.val.push({name:this.name,value: this.value});
            }
        })
        return jQuery.param(aa.val);
    };

    function PostForm(keyvalue)
    {
        //需要提交审批人
        if ($("#CustomMember").length > 0) {
            if ($("#CustomMember").val() == "") {
                $.messageBox5s("提示", "必须指派审批人");
                return false;
            }
        }

        $("#AttrZ").val(keyvalue);

        $.ajax({
            url: "@Url.Action("CreateExternal")",
            type: "Post",
            data: $("#flowform").serialize(),
            dataType: "json",
            success: function (data) {
                if (data.type == 1) {
                    var childWindow = $("#ywForm")[0].contentWindow;
                    childWindow.updateState($("#flowform input[id=Id]").val(), '@Model.FormId', 2);
                }
                else {
                    window.parent.frameReturnByMes(data.message);
                }
            }
        });
    }

    $(function () {
        $("#btnQueryFlow").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='auto' frameborder='0' src='/Flow/Form/Details?id=" +"@(Model.FormId)" + "&Ieguid=" + GetGuid() + "'></iframe>");
            $("#modalwindow").window({ title: '流程图', width: 600, height: 420, iconCls: 'fa fa-list' }).window('open');
        });

        $("#btnFlowReturn").click(function () {
            ReturnByReload(true);
            ReturnByClose();
        });
    });

    function ReturnByReload(flag) {
        window.parent.frameReturnByReload(flag);        
    }

    function ReturnByClose() {
        window.parent.frameReturnByClose();
    }

    function ReturnByMes(mes) {
        window.parent.frameReturnByMes(mes);
    }
</script>
<div  class="easyui-panel"   style="width:99%;padding:0px;">

    <form id="flowform">
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.FormId)
        @Html.HiddenFor(model => model.UserId)
        @Html.HiddenFor(model => model.AttrZ)
        <input id="CreateTime" type="hidden" name="CreateTime" value="2000-1-1" />
        <input id="TimeOut" type="hidden" name="TimeOut" value="2111-1-1" />
        <input id="Title" type="hidden" name="Title" value="User Post" />
        <table class="mvctool bgb" style="width:100%;padding:0px">
            <tr>
                <td>
                    <div class="mvctool bgb" style="width:100%;">
                        @Html.FlowToolButton("btnSave", "fa fa-save", Resource.Save, ref perm, "Create", true)
                        @Html.FlowToolButton("btnSubmit", "fa fa-sign-in", Resource.Submit, ref perm, "Create", true)
                        @Html.FlowToolButton("btnQueryFlow", "fa fa-reorder", "流程图", ref perm, "Create", true)
                        @Html.ToolButton("btnFlowReturn", "fa fa-reply", Resource.Reply, false)
                    </div>
                </td>
                @if (ViewBag.Checker == null)
                {
                    <th style='width:100px; text-align:right;'>
                        下一步审批人
                    </th>
                    <td>
                        @Html.HiddenFor(model => model.CustomMember)
                        <input id="CustomMemberList" name="CustomMemberList" readonly="readonly" type="text" style="width: 90px; display: inline; background: #dedede; ">
                        <a class="fa fa-plus-square color-gray fa-lg" id="selExc" href="javascript:void(0)"></a>
                        <script type="text/javascript">
                            $(function () {
                                $("#selExc").click(function () {
                                    $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/SysHelper/UserLookUp?key=CustomMember&val=CustomMemberList'></iframe>");
                                    $("#modalwindow").window({ title: '选择人员', width: 720, height: 428, iconCls: 'fa fa-plus' }).window('open');
                                });
                            });

                            function SetSelResult(result, resultName, key, val) {
                                $("#" + key).val(result);
                                $("#" + val).val(resultName);
                            }
                            function GetSelResult(key, val) {
                                var arrayObj = new Array()
                                arrayObj[0] = $("#" + key).val();
                                arrayObj[1] = $("#" + val).val();
                                return arrayObj;
                            }
                            //ifram 返回
                            function frameReturnByClose() {
                                $("#modalwindow").window('close');
                            }
                        </script>
                    </td>
                }
                else
                {
                    <th></th>
                    <td></td>
                }
                <th style='width:100px; text-align:right;'>紧急程度</th>
                <td>
                    <select name="FormLevel" id="FormLevel" style="width:80px">
                        <option value="@((int)FlowFormLevelEnum.Ordinary)">普通</option>
                        <option value="@((int)FlowFormLevelEnum.Major)">重要</option>
                        <option value="@((int)FlowFormLevelEnum.Urgent)">紧急</option>
                    </select>
                </td>
                <td style="width:10%"></td>
            </tr>
        </table>
    </form> 
</div>
 
 
<div id="setFormLayout" style="width:99%;padding-left:0px;padding-right:0px;padding-top:4px;padding-bottom:4px; overflow-x:hidden;">
    <iframe id="ywForm" src="../../@(html +"/"+ Model.Id)" frameborder="0" style="width:100%; height:100%; overflow-x:hidden;"></iframe>
</div>
 
<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>

<script>
    $(function () {
        $("#setFormLayout").css("width", SetGridWidthSub(40));
        $("#setFormLayout").css("height", SetGridHeightSub(50));

        $("#ywForm").css("height", SetGridWidthSub(30));
        $("#ywForm").css("height", SetGridHeightSub(50));
    })
    //function load(url, data){
    //    $.ajaxSetup({ cache: false });
    //    $("#setFormLayout").load($(url).attr("href"), data, function (result) { 
    //        //将被加载页的JavaScript加载到本页执行
    //        $result = $(result);
    //        $result.find("script").appendTo('#setFormLayout');
    //    });
    //}

    //$("#setFormLayout").click();
</script>

